<template>
  <view class="message-details-page">
    <nav-bar :title="title" @load="handleLoadNav" textAlign="center"></nav-bar>
    <view :style="{ height: viewHeight + 'px' }">
      <custom-scroll-view :loadData="handleLoadData" ref="listRef" emptyText="暂无消息">
        <template v-slot="{data}">
          <message-details-block :data="item" v-for="item in data.data" :type="type" :key="item.id">
          </message-details-block>
        </template>
      </custom-scroll-view>
    </view>
  </view>
</template>

<script>
  import {
    getChatMsgDetailApi
  } from "@/api/message/message.js";
  export default {
    data() {
      return {
        type: "",
        size: 10,
        viewHeight: 0,
        title: ''
      };
    },
    onLoad(e) {
      this.type = e.type;
      this.$nextTick(() => {
        this.$refs.listRef.handleRefresher(true);
        this.title = getApp().globalData.message_config[this.type].configValue;
      })
    },
    methods: {
      handleLoadNav({
        height,
        navHeight
      }) {
        // 可移动视图的高度 = 视图高度 - 导航栏高度
        this.viewHeight = height - navHeight;
      },
      // 加载数据
      async handleLoadData(page) {
        let {
          data: res
        } = await getChatMsgDetailApi(this.type,
          page,
          this.size
        );
        let data = {
          data: res.success ? res.data.records : [],
          pages: res.success ? res.data.pages : 0,
          success: res.success
        };
        return data;
      },
    },
  };
</script>

<style lang="scss" scoped>
  .message-details-page {
    // background-color: #fff;
  }
</style>
